﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using snat.proxy;
using snat.proxy.items.exceptions;

namespace snat.proxy.items {
    public class DBEntity : Item, IComparable {

        public string EntityName { get; private set; }
        public int EntityID { get; private set; }


        public DBEntity(DataRow _row, params DataSet[] _auxilliary)
            : this(_row.Field<int>("EntityID"), _row.Field<string>("EntityName")) { }

        public DBEntity(int _entityId, string _name) {
            this.EntityID = _entityId;
            this.EntityName = _name;
        }

        public override string ToString() {
            if (EntityID == -1) return EntityName;
            else return EntityID + ": " + EntityName;
        }

        public override int GetHashCode() {
            try {
                long res = EntityID + EntityName.GetHashCode() * 2048;
                return res.GetHashCode();
            } catch (ArgumentOutOfRangeException e) {
                Console.WriteLine("Exception :: {0}", e.Message);
                return -1;
            }
        }

        public virtual int CompareTo(object obj) {
            return EntityID.CompareTo((obj as DBEntity).EntityID);
        }

    }
}
